#include "findandreplace.h"
#include "ui_findandreplace.h"
#include <QMessageBox>
#include <QTextDocument>
#include <QLineEdit>
#include <QTextEdit>

FindAndReplace::FindAndReplace(QWidget *parent,QTextEdit* _target) :
    QDialog(parent),
    ui(new Ui::FindAndReplace),target(_target)
{
    ui->setupUi(this);
    connect(ui->PreBtn, SIGNAL(clicked()), this, SLOT(findPre()));
    connect(ui->NextBtn,SIGNAL(clicked()),this,SLOT(findNext()));
}

FindAndReplace::~FindAndReplace()
{
    delete ui;
}


void FindAndReplace::findNext(){
    QString str = ui->Find->text();
    if(str.isEmpty())return;
    if (!target->find(str))
    {
        QMessageBox::warning(this, tr("查找"),
                             tr("找不到呀😯"));
    }
}

void FindAndReplace::findPre(){
    QString str = ui->Find->text();
    if(str.isEmpty())return;
    if (!target->find(str, QTextDocument::FindBackward))
    {
        QMessageBox::warning(this, tr("查找"),
                             tr("找不到呀😯"));
    }
}
